package com.fileshare.web.controller.index.view;

import com.fileshare.web.controller.index.BaseController;
import com.fileshare.web.dto.Vo.ArticleVo;
import com.fileshare.web.dto.info.WebInfo;
import com.fileshare.web.properties.WebProperties;
import com.fileshare.web.service.ArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 开源推荐
 */
@Controller
@RequestMapping("/open")
public class OpenSourceController extends BaseController {
    @Resource
    private WebProperties webProperties;
    @Resource
    private ArticleService articleService;

    @GetMapping("")
    public String home(HttpServletRequest request) {
        PageInfo<ArticleVo> articles = articleService.getArticles(0, webProperties.getLimit());
        request.setAttribute("articles", articles);
        WebInfo info = new WebInfo();
        info.setTitle("FileShare 主页");
        request.setAttribute("webInfo", info);
        return view("open/index");
    }
}
